package com.nuoniu.sibanyun.controller.erp;


import com.nuoniu.sibanyun.common.BaseController;
import com.nuoniu.sibanyun.common.exception.NuoNiuException;
import com.nuoniu.sibanyun.common.lang.StringUtils;
import com.nuoniu.sibanyun.common.result.HttpResult;
import com.nuoniu.sibanyun.entity.erp.ErpBarcodeAttribute;
import com.nuoniu.sibanyun.service.erp.IErpBarcodeAttributeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 条码管理-条码属性 前端控制器
 * </p>
 *
 * @author 小啊刚
 * @since 2021-11-03
 */
@RestController
@RequestMapping("/barcode/attribute")
@Api(tags = "条码管理-条码属性")
public class ErpBarcodeAttributeController extends BaseController {

    @Autowired
    private IErpBarcodeAttributeService barcodeAttributeService;

    @ApiOperation("获取详情")
    @GetMapping("getDetail")
    public HttpResult getDetail(Long id) {
        return HttpResult.ok(barcodeAttributeService.getDetail(id));
    }

    @ApiOperation("获取列表")
    @GetMapping("getList")
    public HttpResult getList() {
        return HttpResult.ok(barcodeAttributeService.getList());
    }

    @ApiOperation("保存")
    @PostMapping("save")
    public HttpResult save(@RequestBody ErpBarcodeAttribute attribute) {
        if(StringUtils.isBlank(attribute.getCode())) {
            throw new NuoNiuException("编码不能为空");
        }

        if(StringUtils.isBlank(attribute.getName())) {
            throw new NuoNiuException("名称不能为空");
        }

        if(attribute.getBarcodeAttributeBos().size() == 0) {
            throw new NuoNiuException("属性业务不能为空");
        }

        barcodeAttributeService.saveAttribute(attribute);
        return HttpResult.ok();
    }

    @ApiOperation("删除")
    @DeleteMapping("delete")
    public HttpResult delete(Long id) {
        barcodeAttributeService.delete(id);
        return HttpResult.ok();
    }
}
